-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow for configuration of foldlevel
similar to Emacs Orgmode
#615
feat: Allow for configuration of foldlevel
similar to Emacs Orgmode
#615
Conversation
As a note it appears github will try to autoclose #599 on the acceptance of this PR, I recommend against that unless you believe this is a sufficient solution. A tighter integration may be desired, read the last bit of the PR for an idea 😉. |
Why not just have a depth variable? With this approach you can: require("orgmode").setup {
fold = {
-- depth = 1, --> custom depth
depth = vim.o.foldlevel, --> respect the options
-- Other fold options ... --
}
} |
Sure, that'd work. I was trying to be compliant with Emacs orgmode, I'm unsure as to how much Nvim Orgmode intends to mirror it. At that point though, why even support a depth variable? We get that for free via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Code looks ok, but I would like it to live on the config class and called in the ftplugin/org.vim
.
lua/orgmode/init.lua
Outdated
elseif config.org_startup_folded == 'showeverything' then | ||
vim.opt_local.foldlevel = 99 | ||
elseif config.org_startup_folded == 'inherit' then | ||
vim.opt_local.foldlevel = vim.opt.foldlevel:get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this. It should inherit it automatically. We just need to not do anything in case of inherit
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point! I will remove that. I'll get to this in a few hours, have a few things I gotta knock out today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done as part of the refactor to place this in the config class. Take a look.
lua/orgmode/init.lua
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not change anything in this file but instead introduce a method on the config called setup_foldlevel()
and call it in the ftplugin/org.vim
as we do for the mappings here
Line 7 in 983fc95
lua require('orgmode.config'):setup_mappings('text_objects') |
lua require('orgmode.config'):setup_foldlevel()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do, will get to this in a few hours when I get a sec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, see the config class now.
d979d92
to
7b8a5be
Compare
7b8a5be
to
f878dfb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's much cleaner now, thanks!
We just need to fix the fallback to be set properly since it won't be correctly set.
lua/orgmode/config/init.lua
Outdated
vim.opt_local.foldlevel = 99 | ||
elseif self.org_startup_folded ~= 'inherit' then | ||
vim.notify("Invalid option passed for 'org_startup_folded'!", vim.log.levels.WARN) | ||
self.org_startup_folded = 'overview' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since config does not have __newindex
metamethod, this will not be set in the correct place.
It should be self.opts.org_startup_folded = 'overview'
.
For the warning message, please use utils.echo_warning
since that's what we use for other warnings so it is consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, done now. Did not know that Orgmode had its own utilities for info/warn/error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
Hey would you like me to go mention this in the ufo issue thread? If you set the setting to |
Sure, go ahead. |
Summary
This PR permits configuration of the default fold level via the setup variable
org_startup_folded
.nvim-ufo
integration (Compatibility with nvim-ufo #599) to a certain degreenvim-ufo
users (such as I) by permitting them to inherit theirvim.opt.foldlevel
instead of using Orgmode's provided fold level. This makes Orgmode play nice withnvim-ufo
. My earlier problems withfillchars
cannot be reproduced at this time, so I consider it a non-issue.DOCS.md
file for the new option. As a note I have not written new documentation to the Orgmode help file. I noticed that it appeared autogenerated so I held off on that until I get some confirmation.Notes
org_startup_folded
with a default value ofoverview
.org_startup_folded
mirrors the values and usage from Emacs equivalent with the same values for configurationFiletype
event as thefoldlevel
is set upon that event matching fororg
file types.vim.cmd.edit()
after Neorg's initial load which will reload the file and retrigger theFiletype
event permitting the event to work as anticipated.lua/orgmode/init.lua
file such that I could access the value ofconfig.org_startup_folded
and set thefoldlevel
accordingly.foldlevel
value with logic embedded directly into thesetup_autocmds
FileType
autocmd. If you dislike that, please do guide me as to where that logic should be placed.org_startup_folded
variable in theDefaultConfig
. This seems to be the only place within theDefaultConfig
where that is done. If this is not desired I can readily rebase and remove the annotation.A Recommendation
If Nvim Orgmode isn't deadset on being a 100% spec accurate implementation of Orgmode (which I suspect it is attempting to be), I would recommend rejecting this PR in favor of using a more Vim-centric way of setting the
foldlevel
.That is, don't even set the
foldlevel
, make the user set it themselves. If they want a differentfoldlevel
for onlyorg
files then they can use anautocmd
or aftplugin
located in their config atafter/ftplugin/org.lua
.On the other hand, if Nvim Orgmode is deadset on being a 100% compliant implementation of Orgmode, then this PR will bring the implementation closer to the spec.
Fin.
Feel free to provide critique and advice, I'm certainly inexperienced in working with Nvim Orgmode's code base, this PR marks the first time I have ever done so. Any thoughts you have are very much desired 😃.
Closes #614
Only partially resolves #599, for a tighter integration we may want to autodetect
nvim-ufo
and set thefoldlevel
accordingly.